import axios from 'axios';
import apiConfig from './api.config';

function send (path, dataContent, isGet = true) {
    return new Promise((resolve, reject) => {

        // var config = {
        //     method: 'post',
        //     url: apiConfig.baseUrlTPX + path,
        //     headers: {
        //         'User-Agent': '',
        //         'Content-Type': 'application/json',
        //         'Accept': '*/*',
        //         'Host': '',
        //         'Connection': 'keep-alive',
        //     },
        //     data: data,
        // };

        let params = dataContent;
        axios({
            url: `./${path}`,
            method: isGet ? 'get' : 'post',
            params: isGet ? params : {},
            data: isGet ? {} : params,
            headers: {
                'Content-Type': 'application/json',
            },
            dataType: "text",
            baseURL: apiConfig.baseUrlTPX,
        }).then((response) => {
            resolve(response.data);
        }).catch((err) => {
            console.log('err :>> ', err);
            reject(err);
        });



        //处理图片路径
        // let params = { dataContent };

        // axios({
        //     url: `./${path}`,
        //     method: isGet ? 'get' : 'post',
        //     params: isGet ? params : {},
        //     data: isGet ? {} : params,
        //     dataType: "text",
        //     baseURL: apiConfig.baseUrl28,
        // }).then((response) => {
        //     resolve(response.data);
        // }).catch(err => {
        //     console.log('err :>> ', err);
        //     reject(err);
        // });
    });
}
const myAxios28TPX = {
    get (path, dataContent) {
        dataContent = dataContent ? dataContent : '{}';
        return send(path, dataContent, true);
    },
    post (path, dataContent) {
        dataContent = dataContent ? dataContent : '{}';
        return send(path, dataContent, false);
    },
};
export default myAxios28TPX;
